/**
*   @file       Pwm_Cfg.c
*   @version    1.0.4
*
*   @brief      AUTOSAR Pwm - Pwm pre-compile configuration file.
*   @details    Pre-compile configuration structure instances.
*
*   @addtogroup PWM_MODULE
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.0 MCAL
*   Platform             : ARM
*   Peripheral           : Ftm
*   Dependencies         : none
*
*   Autosar Version      : 4.0.3
*   Autosar Revision     : ASR_REL_4_0_REV_0003
*   Autosar Conf.Variant :
*   SW Version           : 1.0.4
*   Build Version        : S32K14xS32K14x_MCAL_1_0_4_RTM_ASR_REL_4_0_REV_0003_20190307
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2018-2019 NXP
*   All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifdef __cplusplus
extern "C" {
#endif

/**
* @page misra_violations MISRA-C:2004 violations
*
* @section Pwm_Cfg_C_REF_1
* Violates MISRA 2004 Required Rule 19.15, Precautions shall be taken in order to
* prevent the contents of a header file being included twice. All header files are
* protected against multiple inclusions.
*
* @section Pwm_Cfg_C_REF_2
* Violates MISRA 2004 Required Rule 8.10, external ... could be made static
* The respective code could not be made static because of layers architecture design of the driver.
* 
* @section Pwm_Cfg_C_REF_3
* Violates MISRA 2004 Advisory Rule 19.1, only preprocessor statements and comments
* before "#include". This violation  is not  fixed since  the inclusion  of MemMap.h
* is as  per Autosar  requirement MEMMAP003.
*
* @section Pwm_Cfg_C_REF_4
* Violates MISRA 2004 Required Rule 5.1, Identifiers (internal and external) shall not 
* rely on the significance of more than 31 characters.
* This is not a violation since all the compilers used interpret the identifiers correctly.
*
* @section Pwm_Cfg_C_REF_5
* Violates MISRA 2004 Required Rule 16.9, A function identifier shall only be used with either 
* preceing &, or with a paranhesised parameter list which may be empty.
*
* @section [global]
* Violates MISRA 2004 Required Rule 9.2, Braces shall be used to indicate and match the structure in the
* non-zero initialisation of arrays and structures. At here, we tend to initialized for whole structure, however,
* when configure only 1 controller is configured, tool reported as non-zero initialisation.
*
*/



/*==================================================================================================
*                                         INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/

#include "Pwm.h"
#include "Reg_eSys_Ftm.h"
#include "Reg_eSys_FlexIO.h"
#include "Ftm_Common_Types.h"



/*==================================================================================================
*                               SOURCE FILE VERSION INFORMATION
==================================================================================================*/

/**
* @{
* @file           Pwm_Cfg.c
*/
#define PWM_PC_CFG_VENDOR_ID_C                      43
#define PWM_PC_CFG_MODULE_ID_C                      121
/* @violates @ref Pwm_Cfg_C_REF_4 Identifier exceeds 31 chars. */
#define PWM_PC_CFG_AR_RELEASE_MAJOR_VERSION_C       4
/* @violates @ref Pwm_Cfg_C_REF_4 Identifier exceeds 31 chars. */
#define PWM_PC_CFG_AR_RELEASE_MINOR_VERSION_C       0
/* @violates @ref Pwm_Cfg_C_REF_4 Identifier exceeds 31 chars. */
#define PWM_PC_CFG_AR_RELEASE_REVISION_VERSION_C    3
#define PWM_PC_CFG_SW_MAJOR_VERSION_C               1
#define PWM_PC_CFG_SW_MINOR_VERSION_C               0
#define PWM_PC_CFG_SW_PATCH_VERSION_C               4
/**@}*/



/*==================================================================================================
*                                      FILE VERSION CHECKS
==================================================================================================*/

#if (PWM_PC_CFG_VENDOR_ID_C != PWM_VENDOR_ID)
    #error "Pwm_Cfg.c and Pwm.h have different vendor ids"
#endif

#if ((PWM_PC_CFG_AR_RELEASE_MAJOR_VERSION_C != PWM_AR_RELEASE_MAJOR_VERSION) || \
     (PWM_PC_CFG_AR_RELEASE_MINOR_VERSION_C != PWM_AR_RELEASE_MINOR_VERSION) || \
     (PWM_PC_CFG_AR_RELEASE_REVISION_VERSION_C != PWM_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Pwm_Cfg.c and Pwm.h are different"
#endif

#if ((PWM_PC_CFG_SW_MAJOR_VERSION_C != PWM_SW_MAJOR_VERSION) || \
     (PWM_PC_CFG_SW_MINOR_VERSION_C != PWM_SW_MINOR_VERSION) || \
     (PWM_PC_CFG_SW_PATCH_VERSION_C != PWM_SW_PATCH_VERSION))
    #error "Software Version Numbers of Pwm_Cfg.c and Pwm.h are different"
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if header file and Reg_eSys_FlexIO.h header file are of the same Autosar version */
    #if ((PWM_PC_CFG_AR_RELEASE_MAJOR_VERSION_C != REG_ESYS_FLEXIO_AR_RELEASE_MAJOR_VERSION) || \
         (PWM_PC_CFG_AR_RELEASE_MINOR_VERSION_C != REG_ESYS_FLEXIO_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Pwm_Cfg.c and Reg_eSys_FlexIO.h are different"
    #endif

    /* Check if header file and Reg_eSys_Ftm.h header file are of the same Autosar version */
    #if ((PWM_PC_CFG_AR_RELEASE_MAJOR_VERSION_C != REG_ESYS_FTM_AR_RELEASE_MAJOR_VERSION) || \
         (PWM_PC_CFG_AR_RELEASE_MINOR_VERSION_C != REG_ESYS_FTM_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Pwm_Cfg.c and Reg_eSys_Ftm.h are different"
    #endif

    /* Check if header file and Ftm_Common_Types.h header file are of the same Autosar version */
    #if ((PWM_PC_CFG_AR_RELEASE_MAJOR_VERSION_C != FTM_COMMON_TYPES_AR_RELEASE_MAJOR_VERSION) || \
         (PWM_PC_CFG_AR_RELEASE_MINOR_VERSION_C != FTM_COMMON_TYPES_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Pwm_Cfg.c and Ftm_Common_Types.h are different"
    #endif
#endif



/*==================================================================================================
*                                       GLOBAL CONSTANTS
==================================================================================================*/

#if (PWM_PRECOMPILE_SUPPORT == STD_ON)

/* @violates @ref Pwm_Cfg_C_REF_4 Identifier exceeds 31 chars. */
#define PWM_START_SEC_CONFIG_DATA_UNSPECIFIED
/* @violates @ref Pwm_Cfg_C_REF_1 Precautions to prevent the 
             contents of a header file being included twice. */
#include "MemMap.h"


/*==================================================================================================
*                                  Configuration set PC
==================================================================================================*/

/**
* @brief        Number of configured PWM channels
*
*/
#define PWM_CONF_CHANNELS_PC                            ((uint8)1U)

/**
* @brief        Number of configured FTM modules
*
*/
#define PWM_FTM_MOD_CONFIGS_PC                          ((uint8)1U)

/**
* @brief        Number of configured FTM channels
*
*/
#define PWM_CONF_FTM_CHANNELS_PC                        ((uint8)1U)

/*================================ Configuration for FlexIO ======================================*/

/**
* @brief        No configurations for PWM channels using FlexIO 
*
*/



/*================================= Configuration for FTM =======================================*/

/**
* @brief        Configurations for PWM channels using FTM
*
*/
static CONST(Pwm_Ftm_ChannelConfigType, PWM_CONST) Pwm_Ftm_ChannelConfig_PC[PWM_CONF_FTM_CHANNELS_PC] =
{
    /* Ftm_Channel_0 */
    {
        /** @brief  PWM channel polarity */
        PWM_HIGH,
        /** @brief  PWM channel idle state */
        PWM_LOW,
        /** @brief  Default duty cycle value */
        ((uint16)16384),
        /** @brief  FTM Channel ID */
        FTM_2_CH_0,
#if (PWM_ENABLE_PHASE_SHIFT == STD_ON)
        /** @brief  Default phase shift value */
        ((uint16)0),
#endif
        /** @brief  Edge alignment for the current channel  */
        PWM_EDGE_ALIGNED
    }
};

/**
* @brief        Configurations for FTM modules
*
*/
/* @violates @ref Pwm_Cfg_C_REF_2 external ... could be made static */
static CONST(Pwm_Ftm_ModuleConfigType, PWM_CONST) Pwm_Ftm_ModuleConfig_PC[PWM_FTM_MOD_CONFIGS_PC] =
{
    /* Ftm Module 0 */
    {
        /** @brief  FTM_2_CONF register */
        (FTM_CONF_BDMMODE_ALLRUN_U32 | ((uint32) 0U) | ((uint32) 0)),
        /** @brief  FTM_2_SC register */
        (FTM_SC_CLKS_SYS_CLOCK_U32 | FTM_SC_PS_DIV128_U32 |  ((uint32)1U << (FTM_SC_PWMOUTPUTEN_SHIFT + (uint32)0U ))| ((uint32)0)),
        /** @brief  FTM_2_SYNC register */
        (uint8) (FTM_SYNC_CNTMIN_ENABLE_U32 | ((uint32) 0)),
        /** @brief  FTM_2_MODE register used to enable other features of the FTM */
        (FTM_MODE_INIT_ENABLE_U32 | FTM_MODE_FTMEN_ENABLE_U32 | FTM_MODE_WPDIS_DISABLE_U32 | ((uint32)0)),
        /** @brief  FTM_2_DEADTIME register */
        (FTM_DEADTIME_DTPS_DIV1_U32 | ((uint32) 0U)),
        /** @brief  FTM_2_COMBINE register */
        (FTM_COMBINE_SYNCEN0_ENABLE_U32 | ((uint32) 0)),
        /** @brief  Id of the referenced FTM module: FTM_2 */
        PWM_FTM_2,
        /** @brief  Default period value: , freq = 100.0 Hz: FTM_2_MOD register */
        ((Pwm_PeriodType)6250)
#if (PWM_FAULT_SUPPORTED == STD_ON)
        ,
        /** @brief  FTM_2_FLTCTRL register */
        ((uint32) 0),
        /** @brief  FTM_2_FLTPOL register */
        (((uint32) 0)),
        /** @brief  Fault notification callbacks */
        {NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR}
#endif
    }
};

/**
* @brief        FTM IP configuration
*/
static CONST(Pwm_Ftm_IpConfigType, PWM_CONST) Pwm_Ftm_IpConfig_PC =
{
    /** @brief  Number of FTM channels in the current PWM configuration */
    PWM_CONF_FTM_CHANNELS_PC,
    /** @brief  Number of FTM modules in the current PWM configuration */
    PWM_FTM_MOD_CONFIGS_PC,
    /** @brief  Pointer to the array of FTM enabled PWM channel configurations */
    &Pwm_Ftm_ChannelConfig_PC,
    /** @brief  Pointer to the array of FTM module configurations */
    &Pwm_Ftm_ModuleConfig_PC
};




/*============================== IP Wrapper configuration ===================================*/

/**
* @brief        Array of configured PWM channels 
*
*/
/* @violates @ref Pwm_Cfg_C_REF_2 external ... could be made static */
static CONST(Pwm_ChannelConfigType, PWM_CONST) Pwm_Channels_PC[PWM_CONF_CHANNELS_PC] =
{
    /* Pwm_Led1 */
    {
        /** @brief  Channel class */
        PWM_FIXED_PERIOD
#if (PWM_NOTIFICATION_SUPPORTED == STD_ON)
        ,
        /** @brief  PWM notification function */
        &Pwm_Led1Notification
#endif
    }
};

/**
* @brief        PWM channels IP related configuration array
*
*/
static CONST(Pwm_IpChannelConfigType, PWM_CONST) Pwm_IpChannelConfig_PC[PWM_CONF_CHANNELS_PC] =
{
    /* Pwm_Led1 */
    {
        /** @brief  IP type of this channel */
        PWM_FTM_CHANNEL,
        /** @brief  Index in the configuration table of the FTM channels */
        (uint8)0
    }
};




/*============================== High level configuration ===================================*/

/**
* @brief        PWM high level configuration structure
*
*/
/* @violates @ref Pwm_Cfg_C_REF_2 external ... could be made static */
CONST(Pwm_ConfigType, PWM_CONST) Pwm_InitConfigPc =
{
    /** @brief  Number of configured PWM channels */
    (Pwm_ChannelType)PWM_CONF_CHANNELS_PC,
    /** @brief  Pointer to array of PWM channels */
    &Pwm_Channels_PC,
    /** @brief  IP specific configuration */
    {
        /** @brief  Pointer to the structure containing FlexIO configuration */
        /** @brief  Pointer to the structure containing FTM configuration */
        &Pwm_Ftm_IpConfig_PC,
        /** @brief  Pointer to the structure containing PWM channels IP related configuration array */
        &Pwm_IpChannelConfig_PC
    }
#if (PWM_NOTIFICATION_SUPPORTED == STD_ON)
    ,
    /** @brief Hw to logic channel map. Array containing a number of elements
    equal to total number of available channels on FTM IPV */
    {

        /* Idx of channels 0 - 7 of FTM Module 0 in the array of logic Pwm channels */
        (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255,
        /* Idx of channels 0 - 7 of FTM Module 1 in the array of logic Pwm channels */
        (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255,
        /* Idx of channels 0 - 7 of FTM Module 2 in the array of logic Pwm channels */
        (Pwm_ChannelType)0, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255,
        /* Idx of channels 0 - 7 of FTM Module 3 in the array of logic Pwm channels */
        (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255, (Pwm_ChannelType)255

    }
#endif
};




/* @violates @ref Pwm_Cfg_C_REF_4 Identifier exceeds 31 chars. */
#define PWM_STOP_SEC_CONFIG_DATA_UNSPECIFIED
/* @violates @ref Pwm_Cfg_C_REF_1 Precautions to prevent the
             contents of a header file being included twice. */
/* @violates @ref Pwm_Cfg_C_REF_3 #include statements in a file should
             only be preceded by other preprocessor directives or comments. */
#include "MemMap.h"

#endif  /* PWM_PRECOMPILE_SUPPORT */

#ifdef __cplusplus
}
#endif

/** @} */

